#pragma once

#include "bObject.h"
#include "bArray.h"
#include "bTuple.h"

template<class A>
class ForwardIter
{
protected:
	bReference<A>* base;
public:
	ForwardIter(bReference<A>* src):base(src){}
	operator A*(){ return base->object(); }
	A* operator -> () { return operator A*(); }
	ForwardIter& operator ++ (){ base++;return *this; }
	bool operator==(const ForwardIter& cmp){ return base==cmp.base; }
	bool operator!=(const ForwardIter& cmp){ return base!=cmp.base; }
};

template<class A,class B>
class bMap:public bObject
{
protected:
	bArray<bTuple<A,B> > items;
public:
	bMap(void){}
	typedef ForwardIter<bTuple<A,B> > iterator;
	iterator begin()
	{
		return ForwardIter<bTuple<A,B> >(items.begin());
	}
	iterator end()
	{
		return ForwardIter<bTuple<A,B> >(items.end());
	}
	B* operator [] ( A* cmp)
	{
		for(auto i(begin()),e(end());i!=e;i++)
			if(i->left()==cmp)
				return i->right();
	}
	bMap* operator() ( A*a, B*b)
	{
		items.append(new bTuple<A,B>(a,b));
		return this;
	}
	virtual ~bMap(void){}
};

